package com.bac.rentmap.web.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PathVariableParser {
    public static List<String> getPathVariables(String path, Pattern pattern){
        if(pattern == null)
            return Collections.EMPTY_LIST;
        
        Matcher matcher = pattern.matcher(path);

        if (matcher.find()) {
            System.out.println("found");
            // Get all groups for this match
            List<String> res = new ArrayList<String>(matcher.groupCount() - 1);
            for (int i = 0; i <= matcher.groupCount(); i++) {
                String groupStr = matcher.group(i);
                System.out.println(groupStr);
                if (i != 0) {
                    res.add(groupStr);
                }
            }
            return res;
        }
        else{
            return Collections.EMPTY_LIST;
        }
    }
    public static Pattern createPattern(String controllerBeanName) {
        if(controllerBeanName.contains("*")){
            String regExPattern = controllerBeanName.replace("*", "(.*)");
            return Pattern.compile(regExPattern);
        }
        return null;
    }
}
